package com.kangtu.demoredispublish.listener;

import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

/**
 * @program: demo-redis-publish
 * @description: RedisReceiver
 * @author: david
 * @create: 2021-04-09 12:06
 **/

@Component
public class RedisReceiver implements MessageListener {

    // 继承MessageListener，就能拿到消息体和频道名。
    @Override
    public void onMessage(Message message, byte[] bytes) {
        System.out.println(new String(message.getBody()));
        System.out.println(new String(message.getChannel()));
    }
}
